package com.societyGames.flashForms
{
import com.societyGames.system.EventObject;

import flash.events.Event;

//Container that detects when a child class changes size because of one size change changing the other.
public class ProportionContainer extends SingleItemContainer implements IChangeSize
{
  private var _desiredWidth:Number;
  private var _desiredHeight:Number;
  private var _sizeChangedEventObject:EventObject; //Event

  public function ProportionContainer()
  {
    this._sizeChangedEventObject = new EventObject(this, "SIZE_CHANGED");
  }

  //IChangeSize -->
  public function get sizeChangedEventObject():EventObject
  {
    return this._sizeChangedEventObject;
  }

  //<-- IChangeSize

  public override function set width(value:Number):void
  {
    if (value != this._desiredWidth)
    {
      this._desiredWidth = value;
      if (this._item != null && this._item.width != this._desiredWidth)
      {
        //var oldHeight:Number = this._item.height;
        this._item.width = this._desiredWidth;
        /*if (oldHeight != this._item.height)
         {
         this._sizeChangedEventObject.dispatchEvent();
         }*/
      }
    }
  }

  public override function set height(value:Number):void
  {
    if (value != this._desiredHeight)
    {
      this._desiredHeight = value;
      if (this._item != null && this._item.height != this._desiredHeight)
      {
        //var oldWidth:Number = this._item.width;
        this._item.height = this._desiredHeight;
        /*if (oldWidth != this._item.width)
         {
         this._sizeChangedEventObject.dispatchEvent();
         }*/
      }
    }
  }

  protected override function childSizeChangedHandler(event:Event):void
  {
    this._sizeChangedEventObject.dispatchEvent();
  }
}
}